package com.heima.MyflectDemo1;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class MyFlectDemo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //获得class对象
        Class clazz = Class.forName("com.heima.MyflectDemo1.Student");
        //获得constract对象
        Constructor constructor = clazz.getConstructor(String.class, int.class);
        //创建学生对象
        Student zhangsan = (Student) constructor.newInstance("zhangsan", 23);
        System.out.println(zhangsan);
        //如果是private修饰的方法，则需要临时取消检查
        //setAccessible(true)方法取消权限检查---暴力反射（不推荐使用，破坏了开发中的封装的原则）
    }
}
